<?php

class APPRouter extends APPObject
{
	function _($url)
	{
		return $this->build($url);		
	}
	// convert from sef
	function parse(&$uri)
	{
		global $app_request;
		
		$web	=	parse_url($uri);
		$web	=	explode('&',$web['query']);
		for ($i=0; $i<count($web); $i++)
		{
			$p	=	explode('=',$web[$i]);			
			$app_request[$p[0]]	=	$p[1];
		}
	}
	
	// build to sef
	function build($url)
	{
		$CONFIG = new Config();
		if ($CONFIG->sef == 0)
			return $url;
		if (file_exists(PATH_APP_SITE.DS.'router.php'))
		{
			require_once (PATH_APP_SITE.DS.'router.php');
			$web	=	parse_url($url);
			$web	=	explode('&',$web['query']);
			$query	=	array();
			for ($i=0; $i<count($web); $i++)
			{
				$p	=	explode('=',$web[$i]);
				
				@$query[$p[0]]	=	$p[1];
			}
			$app	=	 Request::getCmd('app','feed');
			$func	=	strtolower($app).'BuildRoute';
			$segments	=	$func($query);
			$segments	=	implode('/',$segments);			
			
			$url	=	APPURI::root().$segments.'.'.$CONFIG->sef_suffix;
			return $url;
//			sef_suffix
//			feedBuildRoute
		}
	}
	
	
}
